package com.project.frba.bifront.client.model.format;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.i18n.client.NumberFormat;

public class CurrencyFormatter implements Formatter{

	private Map<Integer, String> currencySymbols = new HashMap<Integer, String>();
	
	public static int ARS = 1;
	public static int USD = 2;
	public static int EUR = 3;
	public static int JPY = 4;
	
	private Integer selectedSymbol = null;
	
	public CurrencyFormatter(){
		currencySymbols.put(ARS, "$");
		currencySymbols.put(USD, "U$S");
		currencySymbols.put(EUR, "€");
		currencySymbols.put(JPY, "¥");
	}
	
	public void setSelectedSymbol(Integer selectedSymbol) {
		this.selectedSymbol = selectedSymbol;
	}

	public String format(String value) {
		double doubleValue = NumberFormat.getFormat("0.00").parse(value);
		NumberFormat fmt = NumberFormat.getCurrencyFormat();
		return fmt.format(doubleValue);
	}
	
	/**
	 * Toma por defecto como moneda el peso argentino.
	 * @return
	 */
	public String currencySymbol(){
		if(selectedSymbol == null){
			return currencySymbols.get(ARS);
		}
		return currencySymbols.get(selectedSymbol);
	}
}
